﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MaxLeaf.Platform.DataContract;
using MaxLeaf.Platform.BLLProxy;
using MaxLeaf.Platform.Functions;

namespace BLLUnitTest
{
    /// <summary>
    /// imStoresReqTest 的摘要说明
    /// </summary>
    [TestClass]
    public class imStoresReqTest
    {
        public imStoresReqTest()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，该上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        //
        // 编写测试时，可以使用以下附加特性:
        //
        // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // 在运行每个测试之前，使用 TestInitialize 来运行代码
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // 在每个测试运行完之后，使用 TestCleanup 来运行代码
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestMethod1()
        {
            SumResult tempFor = new MtnBLLProxy().Sum(new imStoresReqDtlDataModel(), new List<AddInfo> {                        
                    new AddInfo{
                        Name=AddInfoType.Cond,Value=new List<Cond>{
                            new Cond{PropName="ForeignKey",Compare=CompareType.Equal,Value=1}
                        }
                    },
                    new AddInfo{
                            Name= AddInfoType.SumInfo,Value=new List<SumInfo>{
                                new SumInfo{PropName="SubTotal", SumType=SumInfoType.Sum}
                            }
                        }
                    });
            //object model1 = new MtnBLLProxy().SelectByCond(new imStoresReqHdrDataModel { UI_UserID=6  }, new List<AddInfo> {
            //    new AddInfo{ Name = AddInfoType.PageInfo , Value =new PageInfo{ PageIndex =2, PageSize=2}}
            //    ,new AddInfo{ Name = AddInfoType.Cond , Value =new List<Cond>{ new Cond{ PropName ="Posted", Compare = CompareType.Equal,  Value =0}}}
            //}).Data;
            //Assert.AreNotEqual<double>(0, ((imStoresReqHdrDataModel)((List<object>)model1)[0]).Sum_TotAmt);
           
            //imStoresReqHdrDataModel hdr = null;
            //imStoresReqDtlDataModel dtl = null;
            //MtnBLLProxy bll = new MtnBLLProxy();
            //goods_mainDataModel good = new goods_mainDataModel { goods_id = 1, goods_name = "测试物料1" };
            //bll.Add(good);
            //good = new goods_mainDataModel { goods_id = 2, goods_name = "测试物料2" };
            //bll.Add(good);

            //for (int i = 0; i <= 10; i++)
            //{
            //    hdr = new imStoresReqHdrDataModel();
            //    Random rnd = new Random(DateTime.Now.Millisecond);
            //    hdr.DocStatus = rnd.Next(2);
            //    hdr = (imStoresReqHdrDataModel)bll.Add(hdr);


            //    for (int j = 0; j <= rnd.Next(5); j++)
            //    {
            //        if (rnd.Next(2) == 1)
            //        {
            //            dtl = new imStoresReqDtlDataModel { ForeignKey = hdr.Key, GoodsID = 1, Price = rnd.Next(50), ReqQty = rnd.Next(10)  };
            //            dtl.Subtotal = dtl.Price * dtl.ReqQty;
            //            bll.Add(dtl);
            //        }
            //        if (rnd.Next(2) == 1)
            //        {
            //            dtl = new imStoresReqDtlDataModel { ForeignKey = hdr.Key, GoodsID = 2, Price = rnd.Next(30), ReqQty = rnd.Next(20)  };
            //            dtl.Subtotal = dtl.Price * dtl.ReqQty;
            //            bll.Add(dtl);
            //        }
            //    }
            //}

            //hdr = (imStoresReqHdrDataModel)bll.Select(new imStoresReqHdrDataModel(), hdr.Key);
            //Assert.AreEqual<int>(2, hdr.GoodsTypeCount);
            //Assert.AreEqual<int>(3, hdr.GoodsQtyCount);
            //Assert.AreEqual<double>(30, hdr.TotAmt);

        }
    }
}
